import asyncio
import shutil

from fastapi import FastAPI, UploadFile, File
from YoloProcesser import YOLOProcessor

app = FastAPI()


@app.post("/api/img")
async def upload_image(file: UploadFile = File(...)):
    yolo_processor = YOLOProcessor("../yolov8n.pt")
    processed_content = await yolo_processor.process_with_yolo(file)
    # print(processed_content)
    try:
        shutil.rmtree(f'./runs/detect/')
        print("成功删除缓存")
    except OSError as e:
        print(f"Error: {e.strerror}")
    return processed_content

@app.get("/test")
def test():
    return 1111